<?php         
$db = new Database;
$auth = Auth::getAuth('current_user');
$user_id = $auth['id'];
$company_id =  $auth['company_id'];
$user_group = $auth['role'];
$user_groupType = $auth['role_type'];
$position_id = $auth['position_id'];
?>
    <div class="drag" style="position: fixed;left: 0;bottom: 0;top:0;z-index:1000;margin-top:2px;margin: 32px 0px 0px 0px;border-right: 1px solid #ddd; width: 30px; min-height: 100%;background-color: #fff;">
        <?php
        $userAvatarMessage = $db->query("SELECT * FROM tbuser WHERE online='1' and id!='$user_id' and company_id ='$company_id'","array");
        foreach($userAvatarMessage as $imageData){
            $name = $imageData['firstname'].'-'.$imageData['lastname'];
            echo "<a href=\"javascript:void(0)\" onclick=\"javascript:chatWith('".$imageData['firstname']."')\">";
            //echo "<a class='openChat'>";
        echo myAvatar($imageData['extension'],$imageData['id'],"30","30","border:1px solid #ddd;");
            echo "</a>";
            //echo '</a>';
        }
        ?>
    </div>
    <?php if($auth['steps']=="0"){?>
    <div id="modalBox" style="display: none; position: fixed; opacity: 1; z-index: 11000; left: 50%; margin-left: -330px; top: 100px;">
    </div>
    <div id="modalBg" style="display: none; opacity: 0.5;"></div>
    <!-- Help File For the steps -->
    <div class="checklistStep" style="z-index: -10000;position: fixed;right: 0;bottom: 0;top:0;margin: 32px 0px 0px 0px;border-left: 1px solid #ddd; width: 190px; min-height: 100%;overflow: auto;background-color: #fff;">
        <span class="fontGray">Procedures for Step 5</span>
        <div class="hr"></div>
        <a rel="modalBg" name="test" href="#modalBox" class="helpFileForSteps" data-steps="step5" data-action="helpStep5">
            <span class="fontGray">&nbsp;View Help?</span>
        </a>
            <ul>
                    <li class="step5-1 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                        5.1. In creating a form, you have 3 panel the
                        Form Settings, Add fields, and form view.
                        for you 1st step under step 5
                        set/ change a name of Untitled Form by selecting it on the 3rd panel (Form View)
                    </li>
                <li class="step5-2 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.2. Once you clicked that, the tab from 1st panel (Form Settings) will show,
                    then change settings of your current form.
                </li>
                <li class="step5-3 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.3. On the 2nd panel (Add Fields) 
                    click any button to add html object to the 3rd Panel (Form View)
                </li>
                <li class="step5-4 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.4 To update the selected html object just click it from the 3rd panel to change the settings of it
                    on the Field Setting tab of 1st panel ( Form Settings)
                </li>
                <li class="step5-5 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.5. For the last part you need to create a workflow for your form,
                    click the 3rd tab on the form settings.
                </li>
                <li class="step5-6 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.6. On the workflow objects set a processor per flow of your workflow then specify what action did they do
                    when user have a request to approve.
                </li>
                <li class="step5-7 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.7. After you set your workflow click button <button class="button-icon" disabled="disabled"><li class="icon-stop"></li></button> button to end the workflow.
                </li>
                <li class="step5-8 step5" style="padding: 5px;border-bottom: 1px solid #ddd;">
                    5.8. Lastly, After you set your form, you need to save it by click the <button class="button-ok" disabled="disabled"><li class="icon-plus"></li></button> button from the right side bar panel of (Form View).
                </li>
            </ul>
    </div>
    <?php
    }
    // Redirect to the next step if it is done
    if($auth['steps']=="0"){
        $fStep = $db->query("SELECT * FROM tborgchart WHERE company_id='$company_id'","numrows");
        if($fStep!=0&&$auth['steps']=="1"){
            echo '<meta http-equiv="refresh" content="0;url=/formalistic/">';
        }
    }
    
    ?>
    <div class="body_contents">
        <?php if($auth['steps']=="0"){?>
        <div style="text-align: center;">
            <a href="/formalistic/org_chart"><img src="/images/steps/step1.png" style="cursor:pointer;"/></a>
            <a href="/formalistic/administer"><img src="/images/steps/step2.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/user_management"><img src="/images/steps/step3.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/administer?step=4"><img src="/images/steps/step4.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/forms"><img src="/images/steps/step5A.png" style="margin-left: -30px; cursor:pointer;"/></a>
        </div>
        <?php } ?>
        <?php if($auth['steps']!="0"){ ?>
        <div class="titleBar">
                <div class="left">
                   <div class="titlePosition">
                        FORM TITLES
                   </div>
                </div>
                <div class="right align_right">
                </div>
             </div>
            <div class="Holdercontent MyRequestBox" style="min-height: 100px;">
                <div class="top">
                    <?php
                    $numrows = $db->query("SELECT * from tbform where company_id='$company_id' and is_active = 1","numrows");
                    $query_forms = $db->query("SELECT * from tbform where company_id='$company_id' and is_active = 1","array");
                    ?>
                    <table class="table_data">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Form Title</th>
                                <th>Date</th>
                                <th>Status</th>
                                <th colspan="3">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            if($numrows>0){
                                foreach($query_forms as $row_forms){
                            ?>
                          <tr class="" id="" rel="" title="">
                            <td><?php echo $row_forms['id']; ?></td>
                            <td><?php echo $row_forms['form_title']; ?></td>
                            <td><?php echo $row_forms['date_done']; ?></td>
                            <td><?php echo status($row_forms['is_active']); ?></td>
                            <?php
                            echo statCol($row_forms['is_active'],$row_forms['id'],"forms");
                            ?>
                          </tr>
                          <?php
                                }
                            }else{
                                ?>
                                <tr><td colspan="7" style="text-align: center">No Form Found</td></tr>
                                <?php
                            }
                          ?>
                        </tbody>
                    </table>
                </div>
            </div>
        <?php } ?>
        <div style="float: left;width: 40%;">
            <!-- Form Title -->
            <div class="titleBar">
                <div class="left">
                   <div class="titlePosition">
                        FORM SETTINGS
                        <div style="float: right;margin-top: -3px;">
                            <button class="button-icon setviewCreatedForm tooltip display" title="View Form"><li class="icon-file"></li></button>
                        </div>
                   </div>
                </div>
                <div class="right align_right">
                </div>
             </div>
            <div class="Holdercontent MyRequestBox">
                <div class="top">
                    <ul class="tabs"> 
                        <li class="active fieldsettings tabSetting" rel="tab2" form-status = "1">Field Settings</li>
                        <li class="formsetting tabSetting" rel="tab3" form-status = "1">Form Settings</li>
                        <li class="workflowSettings tabSetting" rel="tab4" form-status = "1">Workflow</li>
                    </ul>
                    <div class="tab_container"> 
                        <div id="tab2" class="tab_content">
                            <h6>No Object is selected </h6>
                        </div>
                        <div id="tab3" class="tab_content">
                            <div class="fields">
                                <div class="label fontGray" id='labelObject'>Form Name:</div>
                                <div class="input_position"><input type="text" class="input-x-medium formName" value="Untitled Form"></div>
                            </div>
                            <div class="fields">
                                <div class="label fontGray" id='labelObject'>Description:</div>
                                <div class="input_position">
                                    <textarea class="formDesc input-x-medium">This is my form. Please fill it out. It's awesome!</textarea>   
                                </div>
                            </div>
                            <div class="fields">
                                <div class="label fontGray" id='labelObject'>Label Placement:</div>
                                <div class="input_position">
                                    <select class="select input-x-medium" id="formLabelAlign" autocomplete="off" <!--onchange="updateForm($F(this), 'LabelAlign')"-->>
                                        <option value="left">Left Aligned</option>
                                        <option value="center">Center Aligned</option>
                                        <option value="right">Right Aligned</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fields">
                                <div class="label fontGray" id='labelObject'>Status of request if the processor is updated:</div>
                                <div class="input_position">
                                    <select class="select input-x-medium confRequest" id="" autocomplete="off" <!--onchange="updateForm($F(this), 'LabelAlign')"-->>
                                        <option value="0">--Select--</option>
                                        <option value="1">Back to the First Processor</option>
                                        <option value="2">Jump to the Next Processor</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fields">
                                <div class="label fontGray" id='labelObject'>Users:</div>
                                <div class="input_position">
                                    <div style="margin-top: 10px;">
                                        <label class="checkbox"><input type="checkbox" class="usersForm allUsers" value="allUsers"/>All Users</label> <br />
                                        <div style="margin-left: 20px;">
                                            <label><span class="icon-plus formUser" rel="getDepartmentFF" id="getDepartmentFF"></span> Department</label> <br />
                                            <div style="margin-left: 20px;">
                                                <span class="span getDepartmentFF" style="display: none;">
                                                    <?php
                                                    $getDepartment = $db->query("SELECT * FROM tborgchart o LEFT JOIN tborgchartobjects oo on o.id=oo.orgChart_id WHERE o.status=1 and o.company_id='$company_id'","array");
                                                    foreach($getDepartment as $setDepartment){
                                                        ?>
                                                        <label class="checkbox"><input type="checkbox"  class="usersForm usersType usersDept" value="<?php echo $setDepartment['role'] ?>"/><?php echo $setDepartment['role'] ?></label><br />
                                                        <?php
                                                    }
                                                    ?>
                                                </span>
                                            </div>
                                            <label><span class="icon-plus formUser" rel="getPositionFF" id="getPositionFF"></span> Position</label><br />
                                            <div style="margin-left: 20px;">
                                                <span class="span getPositionFF" style="display: none;">
                                                    <?php
                                                    $getPosition = $db->query("SELECT * FROM tbposition WHERE company_id='$company_id' and is_active=1","array");
                                                    foreach($getPosition as $setPosition){
                                                        ?>
                                                        <label class="checkbox"><input type="checkbox" class="usersForm usersType" value="<?php echo "pos_".$setPosition['id'] ?>"/><?php echo $setPosition['position'] ?></label><br />
                                                        <?php
                                                    }
                                                    ?>
                                                </span>
                                            </div>
                                            <label><span class="icon-plus formUser" rel="getUserFF" id="getUserFF"></span> User</label><br />
                                            <div style="margin-left: 20px;">
                                                <span class="span getUserFF" style="display: none;">
                                                    <?php
                                                    $getUsers = $db->query("SELECT * from tbuser where status = 1 and company_id = '$company_id' and is_active = 1","array");
                                                    foreach($getUsers as $setUsers){
                                                        ?>
                                                        <label class="checkbox"><input type="checkbox"  class="usersForm usersType" value="<?php echo $setUsers['id'] ?>"/><?php echo setName($setUsers['firstname'],"",$setUsers['lastname']); ?></label><br />
                                                        <?php
                                                    }
                                                    ?>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            
                            
                        </div>
                        <div id="tab4" class="tab_content wofkflowTab">
                            <span class="fontGray">Work Flow Objects</span>
                            <div class='fields'>
                                <div class='label ' id='labelObject'>Processor Type:</div>
                                <div class='input_position'>
                                    <select class="input-x-medium approverTypeWorkflow" style="margin-bottom: 0px;margin-right: 3px">
                                        <option value="0">--Select--</option>
                                        <option value="1">Group Position</option>
                                        <option value="2">Position in the Company</option>
                                        <option value="3">Specific User</option>
                                    </select>
                                </div>
                            </div>
                            <div class='fields'>
                                <div class='label' id='labelObject'>Processor:</div>
                                <div class='input_position'>
                                    <select class="input-x-medium approverWorkflow" style="margin-bottom: 0px;margin-right: 3px">
                                        <option value="0">--Select--</option>
                                    </select>
                                </div>
                            </div>
                            <div class='fields'>
                                <div class='label ' id='labelObject'>Action Status:</div>
                                <div class='input_position'>
                                    <?php
                                    $getApproverStatus = $db->query("SELECT * FROM tbapproverstatus where company_id = '$company_id'","array");
                                    $getApproverStatusCount = $db->query("SELECT * FROM tbapproverstatus where company_id = '$company_id'","numrows");
                                    ?>
                                    <select class="input-x-medium approverWorkflowStatus" style="margin-bottom: 0px;margin-right: 3px">
                                        <?php
                                        if($getApproverStatusCount>0){
                                            ?>
                                            <option value="0">--Select--</option>
                                            <?php
                                            foreach($getApproverStatus as $setApproverStatus){
                                                ?>
                                                <option value="<?php echo $setApproverStatus['id']; ?>"><?php echo $setApproverStatus['approverStatus']; ?></option>
                                                <?php
                                            }
                                        }else{
                                            ?>
                                            <option value="0">--Select--</option>
                                            <?php
                                        }
                                        ?>
                                        
                                    </select>
                                </div>
                            </div>
                            <div class='fields'>
                                <div class='label ' id='labelObject'>Processor Buttons:</div>
                                <div class='input_position'>
                                    <select class="input-x-medium approverButtons" style="margin-bottom: 0px;margin-right: 3px">
                                        <option value="0">--Select--</option>
                                        <?php
                                        $getButtons = $db->query("SELECT * FROM tbbuttons where company_id='$company_id' and is_active=1","array");
                                        foreach($getButtons as $setButtons){
                                          ?>
                                          <option value="<?php echo $setButtons['id']; ?>" id="approverButton_<?php echo $setButtons['id']; ?>"><?php echo $setButtons['button']; ?></option>
                                          <?php  
                                        }
                                        ?>
                                    </select>
                                </div>
                                <div class="addButton" style="float: left;margin: 10px;cursor: pointer;color: #0000ff">Add Button</div>
                            </div>
                            <div class="appendButtonsToUse">
                                
                            </div>
                            <!--br /><br />
                            <label>Status:</label>
                            <select class="statusWorkflow" style="">
                                <option value="0">--Select Status--</option>
                            </select-->
                            <br />
                            <button class="button-btn shapes" id="worklow" rel="workflow" style="float:left;margin-top: 10px;">Add</button>
                            <!--div class="conditionDiv">
                                <label>Fields</label>
                                <select class="formLabels" style="">
                                    <option>--Select Field--</option>
                                </select>
                            </div>
                            <input type="button" class="btn shapes" id="worklow" rel="workflowCondition" value="Add Condition"-->
                        </div>
                    </div>
                </div>
                <div class="down">
                   
                </div>
            </div>
        </div>
        <div style="float: left;width: 58.5%;margin-bottom: 10px;margin-left: 10px;">
                <!-- Form Title -->
                <div class="titleBar">
                    <div class="left">
                       <div class="titlePosition">
                            ADD FIELDS
                       </div>
                    </div>
                    <div class="right align_right">
                    </div>
                 </div>
                <div class="Holdercontent MyRequestBox" style="min-height: 334px;">
                    <div class="top">
                        <span class="fontGray">HTML OBJECTS</span>
                        <div class="hr"></div>
                        <?php
                            $db = new Database();
                            $query = $db->query("SELECT * from tbdefault_fields where fieldClassification=1 AND is_active='1'","array");
                            $start = 1;
                            foreach($query as $row){
                                //if($row['id']%2==1){
                                    //echo "<p>";
                                //}
                                if($row['icon']!="" && $row['btnType']==""){
                                ?>
                                    <button title="<?php echo $row['field'];?>" class="button-btn objects" ftc="<?php echo $row['ftc']; ?>" >
                                        <i class="<?php echo $row['icon']; ?>"></i>
                                          <?php echo $row['field']; ?>
                                    </button>
                                <?php
                                }else{
                                ?>
                                    <button title="<?php echo $row['field'];?>" class="button-btn <?php echo $row['btnType']; ?> objects" ftc="<?php echo $row['ftc']; ?>">
                                        <?php echo $row['field']; ?>
                                    </button>
                                <?php   
                                }
                                //if($row['id']%2==0){
                                    //echo "</p>";
                                //}
                                $start++;
                            }
                        ?>
                        <?php
                            $query = $db->query("SELECT * from tbdefault_fields where fieldClassification=2 AND is_active='1'","array");
                            foreach($query as $row){
                                //if($row['id']%2==0){
                                    //echo "<p>";
                                //}
                                if($row['icon']!="" && $row['btnType']==""){
                                ?>
                                    <button title="<?php echo $row['field'];?>" class="button-btn objects " ftc="<?php echo $row['ftc']; ?>" >
                                        <i class="<?php echo $row['icon']; ?>"></i>
                                            <?php echo $row['field']; ?>
                                    </button>
                                <?php
                                }else{
                                ?>
                                    <button title="<?php echo $row['field'];?>" class="button-btn <?php echo $row['btnType']; ?> objects" ftc="<?php echo $row['ftc']; ?>">
                                        <?php echo $row['field']; ?>
                                    </button>
                                <?php
                                }
                                //if($row['id']%2==1){
                                    ?>
                                    <!--/p-->
                                    <?php
                                //}
                            }
                        ?>
                    </div>
                </div>
        </div>
        
            <div class="titleBar">
                <div class="left">
                   <div class="titlePosition">
                        <label class="editFormLabel">FORM VIEW</label>
                        <div style="float: right;margin-top: -3px;" class="createform">
                            <button id="endOfDiagram" rel="endOfDiagram" title="End Of Diagram" class="button-icon wfClass actionBtn shapes menuMaintContainer display"><li class="icon-stop"></li></button>
                            <button id="terminator-symbol" rel="newDiagram" title="New Worflow" class="button-icon wfClass actionBtn menuMaintContainer display"><li class="icon-align-justify"></li></button>
                            <button id="delete" rel="delete" title="Delete node" class="button-icon actionBtn wfClass menuMaintContainer display"><li class="icon-trash"></li></button>
                            <button id="printDiagram" rel="print" title="Print Diagram" class="button-icon wfClass actionBtn menuMaintContainer display"><li class="icon-print"></li></button>
                            <button id="zoomInDiagram" rel="zIn" title="Zoom In" class="button-icon actionBtn wfClass menuMaintContainer display"><li class="icon-zoom-in"></li></button>
                            <button id="zoomOutDiagram" rel="zOut" title="Zoom Out" class="button-icon actionBtn wfClass menuMaintContainer display"><li class="icon-zoom-out"></li></button>
                            <button class="button-icon actionBtn save_form" update = "0" title="Save Created Form"><li class="icon-ok"></li></button>
                        </div>
                        <div style="float: right;margin-top: -3px; display: none;" class="editForm">
                            <!--button class="button-icon actionBtn saveEdit_forms" title="Save Updated Form"><li class="icon-ok"></li></button-->
                            <button style="margin-right: 3px" class="button-icon actionBtn closeNewForm" title="Close"><li class="icon-remove"></li></button>
                        </div>
                   </div>
                </div>
             </div>
            <div class="Holdercontent MyRequestBox">
                <!-- Contents here -->
                <div class="forForm">
                    <a href="#tab3" data-toggle="tab" class="formtitleHolder" rel="tab3">
                        <span id='head' class='span12 setObjectForm borderDashed'>
                            <h4 style="cursor: pointer;color: #000;font-weight: bold;" class="formTitleText" align="left">Untitled Form</h4><br />
                            <p style="color: #555;" class="formDescText">This is my form. Please fill it out. It's awesome!</p>
                        </span>
                    </a>
                    <div class="top mainContent drag">
                        
                        <br />
                    </div>
                    
                </div>
                <!-- Edit Form -->
                <div class="editFormContent">
                    
                </div>
                <!-- For WorkFlow -->
                <div class="main_container" style="display: none;background-color: #FFF">
                    <span class="actionHolder">
                        <!--img src="/images/flowchart/decision-symbol.png" id="terminator-symbol" rel="decision" height="15" width="20" title="Desision" class="actionBtn shapes"-->
                        <!--img src="/images/flowchart/end.png" id="endOfDiagram" rel="endOfDiagram" title="End Of Diagram" class="actionBtn shapes">
                        <img src="/images/flowchart/new_diagram.png" id="terminator-symbol" rel="newDiagram" title="New Worflow" class="actionBtn">
                        <img src="/images/flowchart/del_node.png" id="delete" rel="delete" title="Delete node" class="actionBtn">
                        <img src="/images/flowchart/print_diagram.png" id="printDiagram" rel="print" title="Print Diagram" class="actionBtn">
                        <img src="/images/flowchart/zoom_in_diagram.png" id="zoomInDiagram" rel="zIn" title="Zoom In" class="actionBtn">
                        <img src="/images/flowchart/zoom_out_diagram.png" id="zoomOutDiagram" rel="zOut" title="Zoom Out" class="actionBtn"-->
                    </span>
                    <div class="flow_content">
                        <!--Start-->
                        <span class="appendShapes workflowObjects appendObjects" node-type="start" diagram-type="workflow" rel="notAllowed" id="flowspan_1_worklow" style="left: 10px;top: 15px">
                        <span id="spanText_1" class="textHandle" style="cursor:pointer;position: absolute;margin: 12px;width: 60px;text-align: center;font-size: large">START</span>
                          <span id="flow_1_worklow" rel="1" class="fl_shapes"></span>
                          <span style="position:absolute" class="shapeSideButton_holder">
                              <span style="" class="right connector"  id="right_1_worklow"></span>
                          </span>
                        </span>
                    </div>
                </div>
            </div>
    </div>
    <script>
        setActivNav("administer");
    </script>